﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace System.Web.Mvc
{
    public static class Helper
    {
        public static MvcHtmlString DropDownList(this HtmlHelper htmlHelper, string name, Dictionary<string, string> val, string select, IDictionary<string, object> htmlAttributes = null)
        {
            StringBuilder tag = new StringBuilder();

            tag.Append(string.Format("<select name=\"{0}\" id=\"{0}\">", name));

            foreach (var item in val)
                tag.Append(
                    string.Format("<option {0} value=\"{2}\">{1}</option>", item.Value == select ? "selected" : string.Empty,
                    item.Key,
                    item.Value)
                    );

            tag.Append(string.Format("</select>", name));

            return MvcHtmlString.Create(tag.ToString());
        }
    }
}
